package com.lin.controller;

import com.lin.entity.message.ResponseResult;
import com.lin.entity.vo.PlaneDataVo;
import com.lin.service.PlaneService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.Date;
import java.util.List;

@Slf4j
@RestController
@RequestMapping("/map/plane")
public class PlaneController {

    @Autowired
    private PlaneService planeService;


    @GetMapping("/getNewest")
    public ResponseResult getNewest(HttpServletRequest request) {
        return planeService.getNewest(request);
    }

    @GetMapping("/history")
    public ResponseResult history(@RequestParam List<String> tarids) {
        return planeService.history(tarids);
    }

    @GetMapping("/list")
    public ResponseResult list(PlaneDataVo planeDataVo) {
        return planeService.list(planeDataVo);
    }

    @GetMapping("/playback")
    public ResponseResult playback(PlaneDataVo planeDataVo) {
        return planeService.playback(planeDataVo);
    }

    @GetMapping("/tracePlaneInfo")
    public ResponseResult tracePlaneInfo(HttpServletRequest request) {
        return planeService.getTracePlaneInfo(request);
    }

    @GetMapping("/getTraceOnPlayback")
    public ResponseResult getTraceOnPlayback(
            @RequestParam(value = "startTime", required = false) @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") Date startTime,
            @RequestParam(value = "tarid", required = false) String tarid) {

        log.info("开始时间：{}，目标id：{}", startTime, tarid);
        return planeService.getTraceOnPlayback(startTime, tarid);
    }
}
